package com.dayu.helper;

import java.util.prefs.Preferences;

public class ConfigHelper {

    private static final Preferences prefs = Preferences.userNodeForPackage(ConfigHelper.class);

    private static final String DB_TYPE_KEY = "dbType";
    private static final String DB_URL_KEY = "dbUrl";
    private static final String DB_USER_KEY = "dbUser";
    private static final String DB_PWD_KEY = "dbPwd";
    private static final String DB_INIT_KEY = "dbInit";

    public static void saveConfig(String dbType, String dbUrl, String dbUser, String dbPwd, String dbInit) {
        prefs.put(DB_TYPE_KEY, dbType);
        prefs.put(DB_URL_KEY, dbUrl);
        prefs.put(DB_USER_KEY, dbUser);
        prefs.put(DB_PWD_KEY, dbPwd);
        prefs.put(DB_INIT_KEY, dbInit);
    }

    public static String getDbType() {
        return prefs.get(DB_TYPE_KEY, null);
    }

    public static String getDbUrl() {
        return prefs.get(DB_URL_KEY, null);
    }

    public static String getDbUser() {
        return prefs.get(DB_USER_KEY, null);
    }

    public static String getDbPwd() {
        return prefs.get(DB_PWD_KEY, null);
    }

    public static String getDbInit() {
        return prefs.get(DB_INIT_KEY, null);
    }

    public static boolean hasConfig() {
        return getDbType() != null && getDbUrl() != null && getDbUser() != null && getDbPwd() != null;
    }
}
